/**
  * 迭代计算一个数组元素的所有子集
  * @param arr 输入将要获取子集的数组
  * @return {T[][]} 返回子集集合
  */
export const subset = <T>(arr: T[]) => {
  const res: T[][] = [[]];

  for (let i = 0; i < arr.length; i += 1) {
    const len = res.length;
    for (let j = 0; j < len; j += 1) {
      const sub: T[] = [...res[j]];
      sub.push(arr[i]);
      res.push(sub);
    }
  }
  return res;
};

export default { subset };
